from datetime import datetime, timedelta
from typing import Optional

from app.core.constants import TriggerType
from app.core.task.triggers.base import BaseTrigger
from app.utils.timezone import now


class DelayTrigger(BaseTrigger):
    trigger_type = TriggerType.DELAY

    def __init__(self, delay_seconds: int):
        super().__init__(delay_seconds=delay_seconds)

    async def get_next_fire_time(self, previous_fire_time: Optional[datetime]) -> Optional[datetime]:
        base_time = previous_fire_time or now()
        return base_time + timedelta(seconds=self.params["delay_seconds"])
